package apIExercise.io;

import java.io.*;

/**
 * 文件复制：将一个 文件中的数据读出来，然后再写入另一个文件
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        /*
        FileInputStream fis=new FileInputStream("./blr.jpg");
        FileOutputStream fos=new FileOutputStream("blr_02.jpg");
        long start=System.currentTimeMillis();
         */
        /*
        byte[] data=new byte[1024*10];
        int len;
        while ((len=fis.read(data))!=-1){
            fos.write(data);
        }

         */
        /*
        int len;
        byte[] data=new byte[1024*10];
        while ((len=fis.read(data))!=-1){
            fos.write(data,0,len);
        }
        long end=System.currentTimeMillis();
        System.out.println("复制成功！"+(end-start)+"毫秒");
        fis.close();
        fos.close();

         */
        /*
        File file=new File("blr.jpg");
        FileInputStream fis=new FileInputStream(file);
        FileOutputStream fos=new FileOutputStream("blr_02.jpg");
        long start=System.currentTimeMillis();
        int line;
        byte[] data=new byte[1024*10];
        while ((line=fis.read(data))!=-1){
            fos.write(data,0,line);
        }
        long end=System.currentTimeMillis();
        System.out.println("复制完毕！"+(end-start)+"ms");
        fis.close();
        fos.close();

         */
        /*
        File file = new File("blr.jpg");
        FileInputStream fis = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream("blr_02.jpg");
        long start = System.currentTimeMillis();
        byte[] data = new byte[1024 * 10];
        while ((fis.read(data)) != -1) {
            fos.write(data);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！" + (end - start) + "ms");
        fis.close();
        fos.close();
         */
        File file = new File("blr.jpg");
        FileInputStream fis = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream("blr_02.jpg");
        long start = System.currentTimeMillis();
        int line;
        byte[] data=new byte[1024*10];
        while ((line=fis.read(data))!=-1){
            fos.write(data,0,line);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！" + (end - start) + "ms");
        fis.close();
        fos.close();
    }
}
